package edu.sysu.demo.petstore.dog.web.rest;

import static org.assertj.core.api.Assertions.assertThat;

import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;

@Slf4j
public class KeyControllerIT {

  private TestRestTemplate restTemplate;

  @Before
  public void setUp() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setOutputStreaming(false);

    restTemplate = new TestRestTemplate(
        new RestTemplateBuilder().requestFactory(() -> requestFactory));
  }

  @Test
  public void publicKey() {
    ResponseEntity<String> entity = restTemplate
        .getForEntity(Location.PUBLIC_KEY.getUrl(), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).isNotBlank();
    log.info("Public Key: {}", entity.getBody());
  }
}